<template>
	<view class="container">
		<view class="title">
			<view>
				请上传头像
				<view>
					请上传近期正面照，正确上传示例
				</view>
			</view>
		</view>
		<view class="form">
			<view class="warn">
				<view class="">
					<image src="@/static/mine/certification/jg.png" mode=""></image>
				</view>
				<text>请上传近期正面照，正确上传示例</text>
			</view>
			<view class="Image">
				<image src="@/static/mine/login/image1.png" mode=""></image>
				<image src="@/static/mine/login/image.png" mode=""></image>
			</view>
			<view class="btn" @click="image()">
				立即上传
			</view>
		</view>
		<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="WRITE_EXTERNAL_STORAGE"></yk-authpup>
		<yk-authpup ref="authpup2" type="top" @changeAuth="changeAuth2" permissionID="CAMERA"></yk-authpup>
	</view>
</template>

<script>
	import {
		createBlindMemberAlbum,
		updateBlindMemberUser
	} from "@/api/user";
	import { CONFIG } from "@/config/app";

	export default {
		data() {
			return {
				formData: {
					radio: false
				},
				Url: CONFIG.HTTP_REQUEST_URL + "app-api/infra/file/uploadPhotos",
			}
		},
		methods: {
			Back() {
				//uni.navigateBack()//默认delta:1
				uni.navigateBack({
					delta: 1, //返回层数，2则上上页
				})
			},
			changeAuth() {
				console.log('权限已授权');
				// #ifdef APP-PLUS
				if (plus.os.name === 'Android') {
					this.$refs['authpup2'].open()
				}
				// #endif
			},
			changeAuth2() {
				console.log('权限已授权');
			},
			
			image() {
				this.$refs['authpup'].open()
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.showLoading({
							title: "上传中"
						});
						for (var i = 0; i < tempFilePaths.length; i++) {
							uni.uploadFile({
								url: this.Url,
								header: {
									'token': uni.getStorageSync('token'),
								},
								filePath: tempFilePaths[i],
								name: 'file',
								success: (uploadFileRes) => {
									uni.hideLoading();
									let data = ''
									if (JSON.parse(uploadFileRes.data).code == 0) {
										updateBlindMemberUser({
											avatar: JSON.parse(uploadFileRes.data).data,
											auditAvatar: JSON.parse(uploadFileRes.data).data
										}).then(res => {
											uni.switchTab({
												url: '/pages/index/index'
											});
										})
									} else {
										uni.showToast({
											title: JSON.parse(uploadFileRes.data).msg,
											icon: "none",
											duration: 2000
										});
									}
								},
								fail: () => {
									uni.hideLoading();
									uni.showToast("上传失败，请联系开发！")
								},
								complete: function() {
									uni.hideLoading();
								}
							});
						}
					}
				});
			},
			goinfo(e, id) {
				if (id) {
					uni.navigateTo({
						url: `./${e}?id=${id}`
					})
				} else {
					uni.navigateTo({
						url: `./${e}`
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.container {
		background-image: url('@/static/mine/login/loginBg.png');
		background-size: 100% 576rpx;
		background-repeat: no-repeat;
		min-height: 100vh;
		padding: 148rpx 30rpx 0;
		box-sizing: border-box;

		.btn {
			margin: 180rpx auto 20rpx;
			width: 515rpx;
			height: 98rpx;
			background: linear-gradient(103deg, #DB88FC 0%, #7B66FE 100%);
			box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(42, 41, 48, 0.35);
			border-radius: 49rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 98rpx;
			text-align: center;
		}

		.warn {
			display: flex;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			justify-content: left;

			image {
				width: 23rpx;
				height: 23rpx;
				margin-right: 11rpx;
				position: relative;
				top: 5rpx;
			}
		}

		.title {
			font-size: 40rpx;
			font-weight: bold;
			color: #333333;

			&>view {
				view {
					margin-top: 17rpx;

					font-size: 30rpx;
					font-weight: 500;
				}
			}
		}

		.form {
			width: 690rpx;
			min-height: 553rpx;
			background: #FFFFFF;
			border-radius: 40rpx;
			margin-top: 59rpx;
			margin-bottom: 25rpx;
			padding: 44rpx 60rpx;
			box-sizing: border-box;

			.Image {
				margin-top: 46rpx;
				display: flex;
				justify-content: space-between;

				image {
					width: 226rpx;
					height: 277rpx;
				}
			}

		}
	}
</style>